package org.kymjs.kjframe.demo;

import android.content.Context;

import java.util.Arrays;
import java.util.Collections;

public class UsbPlugins {

    public void init(Context context) {
        ScreenManager.init(context);
        UsbManage.init(context);
    }

    public boolean connect() {
        return UsbManage.connect();
    }

    // 假设 Usb 类中有 Mouse 静态类并且有相应的方法
    public static boolean click(double x, double y) {
        return UsbManage.click(x, y);
    }

    public static boolean swipe(double x, double y, double ex, double ey) {
        return UsbManage.swipe(x, y, ex, ey);
    }

    public static boolean swipe1(double x, double y, double ex, double ey, double s) {
        return UsbManage.swipe1(x, y, ex, ey, s, 1000);
    }

    public static boolean release() {
        return UsbManage.release();
    }

    public static boolean press(double x, double y) {
        return UsbManage.press(x, y);
    }

    public static boolean paste() {
        UsbManage.sendData(UsbManage.keyReport(0x1, Arrays.asList(0x19)), 1000, true);
        sleep(100);
        UsbManage.sendData(UsbManage.keyReport(0, Arrays.asList(0)), 1000, true);
        return true;
    }

    public static boolean copy() {
        UsbManage.sendData(UsbManage.keyReport(0x1, Arrays.asList(0x06)), 1000, true);
        sleep(100);
        UsbManage.sendData(UsbManage.keyReport(0, Arrays.asList(0)), 1000, true);
        return true;
    }

    public static boolean home() {
        UsbManage.sendData(UsbManage.keyReport(0x8, Arrays.asList(0x28)), 1000, true);
        sleep(100);
        UsbManage.sendData(UsbManage.keyReport(0, Arrays.asList(0)), 1000, true);
        return true;
    }

    public static boolean back() {
        UsbManage.sendData(UsbManage.keyReport(0x5, Arrays.asList(0x2A)), 1000, true);
        sleep(100);
        UsbManage.sendData(UsbManage.keyReport(0, Arrays.asList(0)), 1000, true);
        return true;
    }

    public static boolean enter() {
        UsbManage.sendData(UsbManage.keyReport(0, Arrays.asList(0x28)), 1000, true);
        sleep(100);
        UsbManage.sendData(UsbManage.keyReport(0, Arrays.asList(0)), 1000, true);
        return true;
    }

    public static boolean recent() {
        UsbManage.sendData(UsbManage.keyReport(0x4, Arrays.asList(0x2b)), 1000, true);
        sleep(100);
        UsbManage.sendData(UsbManage.keyReport(0, Arrays.asList(0)), 1000, true);
        return true;
    }

//    public static boolean release() {
//        UsbManage.sendData(UsbManage.keyReport(0, Arrays.asList(0)), 1000, true);
//        return true;
//    }
//
//    public static boolean press(int modifiers, int key) {
//        UsbManage.sendData(UsbManage.keyReport(modifiers, Arrays.asList(key)), 1000, true);
//        return true;
//    }

    public static boolean write(int modifiers, int key) {
        UsbManage.sendData(UsbManage.keyReport(modifiers, Collections.singletonList(key)), 1000, true);
        sleep(100);
        UsbManage.sendData(UsbManage.keyReport(0, Collections.singletonList(0)), 1000, true);
        return true;
    }

    private static void sleep(int millis) {
        try {
            Thread.sleep(millis);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


}
